Editor.Literal = function () {
	var shape;
	var text = '';
	var lang = '';
	var datatype = '';
	var deckEdit;
	var inProperties;
	var impl;
	return {
		init: function (u) {
			inProperties = new Array();
			shape = new Editor.Shape();
			shape.init(this,u);
			shape._resize(Editor.CONFIG.LITERAL_SHAPE_WIDTH, Editor.CONFIG.LITERAL_SHAPE_HEIGHT);
			deckEdit = new Editor.DeckEdit();
			deckEdit.init(shape,u);
			impl = this;
		},
		addInProperties: function (propUuid) {
			inProperties.push(propUuid);
		},
		removeInProperties: function (propUuid) {
			var deleted = false;
			for(var i=0; i<inProperties.length; i++) {
				if (!deleted && inProperties[i] == propUuid) {
					inProperties.splice(i,1);
					deleted = true;
				}
			}
		},
		getTypeClass: function () {
			return "literal";
		},
		getInfo: function () {
			var str = '';
			if (Editor.CONFIG.DEBUG) {
				str = 'Literal:\n';
			}
			str += '@: ' + lang + '\n' + '^^: ' + datatype;
			if (Editor.CONFIG.DEBUG) {
				str += '\n( x:' + this.getX();
				str += ' ; y:' + this.getY();
				str += ' ; w:' + this.getWidth();
				str += ' ; h:' + this.getHeight() + ' )';
				str += '\nuuid: ' + this.getUuid();
			}
			return str;
		},
		getText: function () {
			if (text == '') {
				return '...';
			} else {
				return text;
			}
		},
		setText: function (t) {
			text = t;
		},
		getLang: function () {
			return lang;
		},
		setLang: function (l) {
			lang = l;
		},
		getDatatype: function () {
			return datatype;
		},
		setDatatype: function (d) {
			datatype = d;
		},
		_remove: function () {
			shape._remove(this);
			deckEdit.remove();
		},
		remove: function () {
			var arrProperties = Array();
			for (var i=0;i<inProperties.length;i++) {
				var s = Editor.STATE.SHAPES.get(inProperties[i]);
				if (!s.isDeleted()) {
					arrProperties.push(inProperties[i]);
				}
			}
      var cmd = new JS.Command({
        execute: function () {
					shape.remove(this);
					deckEdit.remove();
					for(var i=0;i<arrProperties.length;i++) {
						var s = Editor.STATE.SHAPES.get(arrProperties[i]);
						if (!s.isDeleted()) {
							s._remove();
						}
					}
        },
        undo: function () {
          impl.draw();
					for(var i=0;i<arrProperties.length;i++) {
						var s = Editor.STATE.SHAPES.get(arrProperties[i]);
						if (s.isDeleted()) {
							s.draw();
						}
					}
        },
        stack: Editor.STATE.CMDSTACK
      });
      cmd.name = 'remove literal';
      cmd.execute();
		},
		draw: function () {
			shape.draw(this);
			deckEdit.draw();
			deckEdit.redraw();
		},
		toFront: function () {
			shape.toFront(this);
			deckEdit.toFront();
            impl.toFrontProperties();
        },
        toFrontProperties: function () {
            for (var i=0;i<inProperties.length;i++) {
                var p = Editor.STATE.SHAPES.get(inProperties[i]);
                if (!p.isDeleted()) {
                    p.toFrontArrowPoint();
                }
            }     
		},
		moveTo: function (x, y) {
			shape.moveTo(x, y);
			this.updateLines();
		},
		translate: function (dx, dy) {
			shape._translate(dx,dy);
			deckEdit.translate(dx,dy);
		},
		_resize: function (dw, dh) {
			shape._resize(dw, dh);
			deckEdit.redraw();
			deckEdit.toFront();
			this.updateLines();
		},
		resize: function (dw, dh) {
			shape.resize(dw, dh);
			deckEdit.redraw();
			deckEdit.toFront();
			this.updateLines();
		},
		updateLines: function () {
          Editor.STATE.SHAPES.forEach(function(pair) {
            if (!pair.value.isDeleted()) {
              var s = pair.value;
                        if (s.getTypeClass() == "property" && s.getUuidEnd() == shape.getUuid()) {
                            s.drawLines();
                        }
            }
          });
		},
    getTextAttr: function () {
      return Editor.CONFIG.SHAPE_ATTR_TEXT;
    },
		figure: function () {
			return Editor.STATE.CANVAS.rect(shape.getX(), shape.getY(), shape.getWidth(), shape.getHeight(), 0).
			attr(Editor.CONFIG.LITERAL_SHAPE_ATTR);
		},
		getShapeAttr: function () {
			return Editor.CONFIG.LITERAL_SHAPE_ATTR;
		},
		getUuid: function () {
			return shape.getUuid();
		},
		isDeleted: function () {
			return shape.isDeleted();
		},
		getX: function () {
			return shape.getX();
		},
		getY: function () {
			return shape.getY();
		},
		getWidth: function () {
			return shape.getWidth();
		},
		getHeight: function () {
			return shape.getHeight();
		},
		toString: function () {
			return 'Literal-->(' + 'Text: ' + text + ' ; ' + 'Lang: ' + lang + ' ; ' + 'Datatype: ' + datatype + ' ; ' + shape.toString() + ')'
		},
		select: function () {
			shape.select(this);
		},
		unselect: function () {
			Editor.Util.unselect(shape);
			shape.unselect();
		},
		frameResize: function () {
			return shape.frameResize();
		},
		saveIni: function (e) {
			shape.saveIni(e);
		},
		getIniPosx: function () {
			return shape.getIniPosx();
		},
		getIniPosy: function () {
			return shape.getIniPosy();
		},
		mousedown: function (e) {
			if (!Editor.Util.isDragging()) {
				shape.mousedown(e);
			}
		},
		mouseover: function () {
			if (!Editor.Util.isDragging()) {
				shape.mouseover();
				deckEdit.mouseover();
			}
		},
		mouseout: function () {
			if (!Editor.Util.isDragging()) {
				shape.mouseout();
				deckEdit.mouseout();
			}
		},
		click: function () {
			if (!Editor.Util.isDragging()) {
				shape.click();
				deckEdit.toFront();
      	impl.toFrontProperties();
			}
		},
		updateText: function () {
			shape.updateText();
		},
		getMinWidth: function () {
			return shape.getMinWidth();
		},
		getMinHeight: function () {
			return shape.getMinHeight();
		},
		showEdit: function () {
			Editor.STATE.SHAPETOUPDATE = this;
			$('#text').val(text);
			$('#lang').val(lang);
			$('#datatype').val(datatype);
			$('#dialogAddLiteral').jqm({overlay: 40, modal: true}).jqmShow();
		},
		getDeckEdit: function () {
			return deckEdit;
		},
		onmouseup: function () {
			this.updateLines();
		},
		getInProperties: function () {
			return inProperties;
		},
		toObject: function () {
			return {
				'type': 'literal',
				'text': text,
				'lang': lang,
				'datatype': datatype,
				'shape': shape.toObject()
			}
		},
	}
}
